package utils;



import java.util.Iterator;
import java.util.List;

import org.eclipse.emf.ecore.EObject;

import fr.obeo.acceleo.ecore.factories.EFactory;
import fr.obeo.acceleo.ecore.factories.FactoryException;
import fr.obeo.acceleo.gen.template.eval.ENodeCastException;

public class Uml14Services {

	/**
	 * Verify if an Element have a stereotype.
	 * Use keyword and profil to find stereotype. 
	 * Multiple stereotype are allow.
	 * @param elt Element used.
	 * @param stereotype Stereotype to search.
	 * @return true if found. false else.
	 * @throws ENodeCastException
	 */
	public boolean hasStereotype(EObject object, String stereotype) throws ENodeCastException, FactoryException {

		// search with real stereotype
		Iterator it = ((List)EFactory.eGet(object,"stereotype")).iterator();
		while (it.hasNext()) {
			EObject element = (EObject)it.next();
			if (stereotype.equals(EFactory.eGet(element,"name"))){
				return true;
			}
		}
		return false;
}


	
	
	public EObject inverseAssociationEnd(EObject object) throws FactoryException {
		EObject end = (EObject)object;
		Iterator it = ((List)EFactory.eGet((EObject)EFactory.eGet(object,"association"),"connection")).iterator();
		while (it.hasNext()) {
			EObject result = (EObject)it.next();
			if (result != end){
				return result;
			}
		}
		return null;
	}
}
